﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;

namespace park.Equipment
{
    public partial class RepeatersEdit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadPageInfo();
            }
        }

        private void LoadPageInfo()
        {
            if (Request.QueryString["id"] != null)
            {
                string id = Request.QueryString["id"];
                cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
                string strJson = sl.GetRepeatersInfoById(id);

                //string strJson = ""
                //    + "{"
                //    + "    \"RepeatersInfo\":"
                //    + "{"
                //    + "        \"ID\":\"001\","
                //    + "        \"No\":\"TSN4564\","
                //    + "        \"Code\":\"GETS7364\","
                //    + "        \"Longitude\":\"86.25\","
                //    + "        \"Latitude\":\"73.19\","
                //    + "        \"CollectorNo\":\"TSN4564\""
                //    + "    }"
                //    + "}";
                JObject obj = JObject.Parse(strJson);

                this.txtNo.Text = obj["RepeatersInfo"]["No"].ToString();
                this.txtCode.Text = obj["RepeatersInfo"]["Code"].ToString();
                this.txtLongitude.Text = obj["RepeatersInfo"]["Longitude"].ToString();
                this.txtLatitude.Text = obj["RepeatersInfo"]["Latitude"].ToString();
                this.txtCollectorNo.Text = obj["RepeatersInfo"]["CollectorNo"].ToString();
                this.hdfID.Value = obj["RepeatersInfo"]["ID"].ToString();

            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string id = this.hdfID.Value;
            string no = this.txtNo.Text;
            string code = this.txtCode.Text;
            string longitude = this.txtLongitude.Text;
            string latitude = this.txtLatitude.Text;
            string collectorNo = this.txtCollectorNo.Text;

            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();

            bool flag = sl.UpdateRepeaters(id, no, code, longitude, latitude, collectorNo);

            if (flag)
            {
                Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert(\"数据保存功能！\")</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert(\"数据保存失败，请重试 ...\")</script>");
            }
        }

    }
}